package com.hhs.storage.controller;


import com.hhs.storage.bean.AttachmentList;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.PermissionItem;
import com.hhs.storage.bean.ResponseInfo;
import com.hhs.storage.service.AttachmentListService;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hhs
 * @since 2023-03-03
 */
@RestController
@RequestMapping("/attachmentList")
public class AttachmentListController {
    @Resource
    private AttachmentListService attachmentListService;

    /**
     * 查询目标id所有附件
     * @return
     */
    @RequestMapping("/queryByTargetId")
    @ResponseBody
    public Map<String,Object> queryByTargetId(InputParam inputParam){
        return attachmentListService.queryByTargetId(inputParam);
    }


    /**
     * 上传目标项目文件
     *
     * @param targetId 目标id
     * @param type 目标类型 0 个人计划,1项目计划
     * @param file 文件
     * @return
     */
    @RequestMapping("/addByTargetId")
    @ResponseBody
    public Map<String,Object> addByTargetId(String permission,@RequestParam String targetId, Integer type, @RequestParam MultipartFile file){
        return attachmentListService.addByTargetId(permission,targetId,type,file);
    }
    /**
     * 加文件权限
     * @param inputParam 目标id
     * @return
     */
    @RequestMapping("/addPermByTargetId")
    @ResponseBody
    public Map<String,Object> addPermByTargetId(@RequestBody InputParam inputParam){
        return attachmentListService.addPermByTargetId(inputParam.getTargetId(),inputParam.getPermissionData());
    }
    /**
     * 设置头像
     * @param url 目标id
     * @return
     */
    @RequestMapping("/setAvatar")
    @ResponseBody
    public Map<String,Object> setAvator(@RequestParam String url){
        return attachmentListService.setAvator(url);
    }
    /**
     * 删除目标项目文件
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> delete(@RequestParam String id){
        return attachmentListService.delete(id);
    }
    /**
     * 下载目标项目文件
     * @param inputParam
     * @return
     */
    @RequestMapping("/downLoad")
    @ResponseBody
    public Map<String,Object> downLoad(InputParam inputParam) throws IOException {
        return attachmentListService.downLoad(inputParam);
    }

    /**
     * 复制方法或粘贴方法
     * @param inputParam
     * @return
     */
    @RequestMapping("/copyOrCut")
    @ResponseBody
    public Map<String,Object> copyOrCut(InputParam inputParam){
        return attachmentListService.copyOrCut(inputParam);
    }

    /**
     * 保存方法
     * @param attachmentList
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public Map<String,Object> edit(AttachmentList attachmentList){
        attachmentListService.saveOrUpdate(attachmentList);
        return ResponseInfo.success();
    }
}

